# -*- coding: utf-8 -*-
# All Rights Reserved 
# @Time    : 2023/10/2520:41
# @File    : analysis.py
__author__ = 'Small Fu'

import os, json
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from tux import topic_1
from tux import topic_2
from tux import topic_3
from tux import topic_7
from tux import topic_5
from tux import topic_4
from tux import topic_6
import code_mysql


class Huitu:
    def __init__(self):
        self.sql = code_mysql.open_mysql()
        if not os.path.exists('static/img'):
            os.mkdir('static/img')

    def salesLineChart(self):
        aa = self.sql.get_all()
        data = pd.DataFrame(
            aa,
            columns=[
                'Rank',
                'Name',
                'Platform',
                'Year',
                'Genre',
                'Publisher',
                'NA_Sales',
                'EU_Sales',
                'JP_Sales',
                'Other_Sales',
                'Global_Sales'],
        )
        data.set_index(['Rank'], inplace=True)
        topic_1.topic_1(data)

    def barChartOfTheTopFive(self):
        aa = self.sql.get_all()
        data = pd.DataFrame(
            aa,
            columns=[
                'Rank',
                'Name',
                'Platform',
                'Year',
                'Genre',
                'Publisher',
                'NA_Sales',
                'EU_Sales',
                'JP_Sales',
                'Other_Sales',
                'Global_Sales'],
        )
        data.set_index(['Rank'], inplace=True)
        topic_2.topic_2(data)

    def averageSalesPerformanceLineChart(self):
        aa = self.sql.get_all()
        data = pd.DataFrame(
            aa,
            columns=[
                'Rank',
                'Name',
                'Platform',
                'Year',
                'Genre',
                'Publisher',
                'NA_Sales',
                'EU_Sales',
                'JP_Sales',
                'Other_Sales',
                'Global_Sales'],
        )
        data.set_index(['Rank'], inplace=True)
        topic_3.topic_3(data)

    def yearAndSales(self):
        aa = self.sql.get_all()
        data = pd.DataFrame(
            aa,
            columns=[
                'Rank',
                'Name',
                'Platform',
                'Year',
                'Genre',
                'Publisher',
                'NA_Sales',
                'EU_Sales',
                'JP_Sales',
                'Other_Sales',
                'Global_Sales'],
        )
        data.set_index(['Rank'], inplace=True)
        topic_4.topic_4(data)

    def numberOfGameTypesDrawingWordClouds(self):
        aa = self.sql.get_all()
        data = pd.DataFrame(
            aa,
            columns=[
                'Rank',
                'Name',
                'Platform',
                'Year',
                'Genre',
                'Publisher',
                'NA_Sales',
                'EU_Sales',
                'JP_Sales',
                'Other_Sales',
                'Global_Sales'],
        )
        data.set_index(['Rank'], inplace=True)
        topic_5.topic_5(data)

    def salesPieChart(self):
        aa = self.sql.get_all()
        data = pd.DataFrame(
            aa,
            columns=[
                'Rank',
                'Name',
                'Platform',
                'Year',
                'Genre',
                'Publisher',
                'NA_Sales',
                'EU_Sales',
                'JP_Sales',
                'Other_Sales',
                'Global_Sales'],
        )
        data.set_index(['Rank'], inplace=True)
        topic_6.topic_6(data)

    def topic_7_bar(self):
        aa = self.sql.get_all()
        data = pd.DataFrame(
            aa,
            columns=[
                'Rank',
                'Name',
                'Platform',
                'Year',
                'Genre',
                'Publisher',
                'NA_Sales',
                'EU_Sales',
                'JP_Sales',
                'Other_Sales',
                'Global_Sales'],
        )
        data.set_index(['Rank'], inplace=True)
        topic_7.topic_7(data)

if __name__ == '__main__':
    huitu = Huitu()
    huitu.topic_7_bar()
